package it.sebsibenal.client.pages;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public class YoutubeVideoPanel extends Composite {

	private static YoutubeVideoPanelUiBinder uiBinder = GWT
			.create(YoutubeVideoPanelUiBinder.class);

	interface YoutubeVideoPanelUiBinder extends UiBinder<Widget, YoutubeVideoPanel> {
	}

	@UiField Element panel;
	int width = 400;
	int height = 325;
	RemoveLinkHandler removeLinkHandler;
	String youtubeCode;
	
	public YoutubeVideoPanel(String youtubeCode) {
		initWidget(uiBinder.createAndBindUi(this));
		this.youtubeCode = youtubeCode;
		panel.setAttribute("src", "http://www.youtube.com/embed/"+youtubeCode);
		panel.setAttribute("width", width+"");
		panel.setAttribute("height", height+"");
	}
	
	@UiHandler("rimuovi")
	public void rimuovi(ClickEvent event) {
		removeLinkHandler.onLinkRemove(youtubeCode);
	}

	public void setRemoveLinkHandler(RemoveLinkHandler removeLinkHandler) {
		this.removeLinkHandler = removeLinkHandler;
	}

	public String getYoutubeCode() {
		return youtubeCode;
	}
	
	
	public interface RemoveLinkHandler {
		void onLinkRemove(String link);
	}
	
}
